import { boot } from 'quasar/wrappers';
import axios from 'axios';
import { LocalStorage } from 'quasar';

const request = axios.create({
  // baseURL: 'http://139.159.184.159:8080/',
  baseURL: 'https://localhost:8080/',
});
export default boot(({ app }) => {
  // for use inside Vue files (Options API) through this.$axios and this.$api

  app.config.globalProperties.$axios = axios;
  // ^ ^ ^ this will allow you to use this.$axios (for Vue Options API form)
  //       so you won't necessarily have to import axios in each vue file

  app.config.globalProperties.$request = request;
  // ^ ^ ^ this will allow you to use this.$request (for Vue Options API form)
  //       so you can easily perform requests against your app's API
});

request.interceptors.request.use(config => {
  const token = LocalStorage.getItem('token')
  if (token) {
    config.headers.token = token
  }
  return config;
}, error => {
  return Promise.reject(error)
})

export { request };
